<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	String path = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath()
			+ "/";
	request.setAttribute("path", path);
%>
<base href="<%=path%>"></base>
<title>新增线路</title>
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/jquery-ui.css">
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery-ui.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<s:form id="ff">
		<table width="800px" height="500px">
			<tr>
				<td><label>线路编码 </label></td>
				<td><s:textfield name="psLine.id" type="hidden"></s:textfield>
					<s:textfield class="easyui-validatebox textbox"
						name="psLine.linecode"
						data-options="required:true,validType:'isExist'"></s:textfield></td>
				<td><label>线路名称</label></td>
				<td><s:textfield class="easyui-validatebox textbox"
						name="psLine.linename" data-options="required:true"></s:textfield></td>
			</tr>
			<tr>
				<td><label>线路长度</label></td>
				<td><s:textfield class="easyui-numberbox textbox"
						name="psLine.linelength" data-options="required:true"></s:textfield></td>
				<td><label>回路长度</label></td>
				<td><s:textfield class="easyui-numberbox textbox"
						name="psLine.backlength" data-options="required:true"></s:textfield></td>
			</tr>
			<tr>
				<td><label>搬运日期</label></td>
				<td><s:textfield class="easyui-datebox textbox"
						name="psLine.productdate" data-options="required:true"></s:textfield></td>
				<td><label>电压等级</label></td>
				<td><s:textfield class="easyui-numberbox textbox"
						name="psLine.voltagelevel" data-options="required:true"></s:textfield></td>
			</tr>
			<tr>
				<td><label>起始杆号</label></td>
				<td><s:textfield class="easyui-combobox textbox"
						name="psLine.startpolecode" data-options="required:true"
						id="startPole" panelHeight='auto'></s:textfield></td>
				<td><label>终止杆号</label></td>
				<td><s:textfield class="easyui-combobox textbox"
						name="psLine.endpolecode" data-options="required:true"
						id="endPole" panelHeight='auto'></s:textfield></td>
			</tr>
			<tr>
				<td><label>塔基数</label></td>
				<td><s:textfield class="easyui-numberbox textbox"
						name="psLine.towerbasenum" data-options="required:true"></s:textfield></td>
				<td><label>备注</label></td>
				<td><s:textarea class="easyui-validatebox textbox"
						name="psLine.common"
						data-options="required:true,validType:'maxLength[10]'"></s:textarea></td>
			</tr>
			<tr>
				<td><label>是否启用</label></td>
				<td><s:radio list="#{'-1':'停用','1':'启用' }" data-options=""
						name="psLine.isstart"></s:radio></td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><input type="button" value="提交" onclick="sub()"></td>
				<td><input type="button" value="返回" onclick="ret()"></td>
			</tr>
		</table>
	</s:form>
	<script type="text/javascript">
		function ret() {
			location.href = "lineManage.jsp";
		}
		function sub() {
			$('#ff')
					.form(
							'submit',
							{
								url : 'line/addUpdateLine',
								onSubmit : function() {
									$('#ff').form('validate');
								},
								success : function(data) {
									var data = eval('(' + data + ')');
									if (!data.success) {
										$.messager.alert('警告', data.message);
									} else {
										$.messager
												.confirm(
														data.message + '，下一步',
														'返回路线管理？',
														function(r) {
															if (r) {
																location.href = "lineManage.jsp";
															}
														});
									}
								}
							});
		}
		$(function() {
			$
					.ajax({
						url : 'pole/findDistinctPoleCode',
						dataType : 'json',
						success : function(d) {
							$('#startPole')
									.combobox(
											{
												data : d,
												valueField : 'value',
												textField : 'value'
												/* filter : function(query, row) {
													var flag = false;
													var key = row.key
															.toString();
													if (key
															&& key
																	.indexOf(query) >= 0) {
														flag = true;
													}
													if (row[$(this).combobox(
															'options').textField]
															.indexOf(query) >= 0) {
														flag = true;
													}
													return flag;
												} */
											});

							$('#endPole').combobox({
								data : d,
								valueField : 'value',
								textField : 'value'
							});

						}
					});

			$.extend($.fn.validatebox.defaults.rules, {
				isExist : {
					validator : function(value, param) {
						var d;
						$.ajax({
							url : 'line/findLineCode',
							async : false,//是否异步执行
							data : {
								'psLine.linecode' : value
							},
							dataType : 'json',
							success : function(data) {
								d = data;
							}
						});
						return !d.success;
					},
					message : '已存在.'
				}
			});
		})
	</script>
</body>
</html>